#include "Bullet.h"
#include "RSManager.h"
#include "Box.h"
#include "Sprite.h"
//thao chinh chut cho nay 0.6f-> 0.3f

#include "GameDefine.h"


Bullet::Bullet():MoveObject(),Object(new Box(D3DXVECTOR2(),D3DXVECTOR2(),D3DXVECTOR2(BULLET_SPEED,BULLET_SPEED)),ObjBullet)
{	
	_id = B_E;
	
}

Bullet::~Bullet()
{
}

void Bullet::init(BULLET_ID id)
{		
	//
	_id = id;
	switch (id)
	{
	case B_R:
		_sprite = RSManager::getInstance()->getSprite(BR);
		break;
	case B_M:
		_sprite = RSManager::getInstance()->getSprite(BM);
		break;
	case B_S:
		_sprite = RSManager::getInstance()->getSprite(BM);
		break;
	case B_F:
		_sprite = RSManager::getInstance()->getSprite(BR);
		break;
	case B_L:
		_sprite = RSManager::getInstance()->getSprite(BL);
		break;
	case B_E:
		_sprite = RSManager::getInstance()->getSprite(BE);
		break;
	}

	_box->_size =  _sprite->getRenderSize();
	this->AssignMove(_box);
}

void Bullet::loaded(ObjectType parent,D3DXVECTOR2 pos, float angle)
{	
	_box->_position = pos;	
	_angle = angle;	
	if(parent == ObjPlayer)
	{
		_obj = ObjBulletPlayer;
		_box->_v.x = _box->_v.y = BULLET_SPEED_PLAYER;
	}
	else
	{
		_obj = ObjBulletEnemy;
		_box->_v.x = _box->_v.y = BULLET_SPEED;
	}	
}

void Bullet::update()
{
	this->moveFollowAngle(this->_angle);	
}

void Bullet::render()
{	
	_sprite->Render(_box->_position);	
}


BULLET_ID Bullet::getType()
{
	return _id;
}



int Bullet::getDamage()
{
	return _damage;
}

Box* Bullet::getCollisionBox()
{
	_colBox->_position = _box->_position;
	_colBox->_v = _box->_v;
	_colBox->_size = _box->_size;
	return _colBox;
}

void Bullet::setDamage(int damg)
{
	_damage = damg;
}
